package code5;

import java.io.BufferedReader;
import java.io.PrintStream;
import java.util.Scanner;


public class ClientSendInformation extends Thread {

    private BufferedReader br;
    private PrintStream ps;
    private Scanner sc;

    public ClientSendInformation(BufferedReader br,PrintStream ps,Scanner sc){
        this.br=br;
        this.ps=ps;
        this.sc=sc;
    }

    @Override
    public void run(){

        while(true){
            System.out.println("请输入要发送的数据内容：");
            String str = sc.nextLine();
            // 当要发送文件时，信息格式是："sendfile 文件路径"
            if(str.contains("sendfile")){
                ps.println(str); // 向服务器端发送包含 "sendfile" 的信息，让服务器启动文件接收线程，准备接收文件
                new ClientSendFile(str).start();
            }else{
                ps.println(str);
                if("bye".equalsIgnoreCase(str)){
                    System.out.println("聊天结束！");
                    break;
                }
            }
        }
    }
}
